package com.railway.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.railway.service.UserService;
import com.railway.service.impl.UserServiceImpl;

/**
 * Servlet implementation class OderLodingServlet
 */
@WebServlet("/OderLodingServlet.do")
public class OderLodingServlet extends HttpServlet {

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("Utf-8");
		HttpSession session = request.getSession();
		if(session.getAttribute("loginUser") != null) {
			response.sendRedirect("login.jsp");
		}else {
			int user_id = 0;
			Map<String,Object> data = new HashMap<String, Object>();
			Map<String,String[]> map = request.getParameterMap();
			Set<String> keys = map.keySet();
			for (String key : keys) {
				data.put(key, map.get(key)[0]);
				if("user_id".equals(key)) {
					user_id = Integer.parseInt(map.get(key)[0]);
				}
			}
			UserService us = new UserServiceImpl();
			data.put("contact", us.selectContact(user_id));
			request.setAttribute("data", data);
			request.getRequestDispatcher("Oder.jsp").forward(request, response);
		}
	}

}
